package com.yulongtian.oneProblemEveryDay.month202302;

/**
 * https://leetcode.cn/problems/longest-well-performing-interval/
 * 双指针方法只通过了42 / 98
 *
 * @author yulongTian
 * @create 2023-02-14 8:43
 */
public class Test11 {
    public static void main(String[] args) {
        int[] hours = {9, 9, 6, 0, 6, 6, 9, 9, 9};
        System.out.println(longestWPI(hours));
    }

    public static int longestWPI(int[] hours) {
        int ans = 0;
        //>8 = 1  <=8 = -1
        for (int i = 0; i < hours.length; i++) {
            if (hours[i] > 8) {
                hours[i] = 1;
            } else {
                hours[i] = -1;
            }
        }
        for (int i = 0; i < hours.length; i++) {
            int sum = 0;
            int j = i;
            for (; j < hours.length; j++) {
                sum += hours[j];
                if (sum > 0) {
                    ans = Math.max(ans, j - i + 1);
                }
            }
        }
        return ans;
    }

}
